package org.shoukaiseki.aqoeous.controller;

import com.google.common.collect.Lists;
import org.shoukaiseki.aqoeous.model.CustomQO;
import org.shoukaiseki.aqoeous.model.ResultModel;
import org.shoukaiseki.aqoeous.model.qo.ItemQO;
import org.shoukaiseki.aqoeous.processor.CustomQOProcessor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.shoukaiseki.aqoeous.builder.AqoeousBuilder.aqoeous;


/**
 * org.shoukaiseki.aqoeous.controller.ShopController
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  19-2-11 下午5:28<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@Controller
public class ItemController {

    @Resource
    CustomQOProcessor customQOProcessor;

    @RequestMapping(path="/aqoeous/item/list2"
            ,produces = "application/json;charset=UTF-8"
//            ,produces ="text/plain;charset=UTF-8"
    )
    @ResponseBody
    public ResultModel shopList2(@RequestParam(required = false) Integer pageSize,
                                @RequestParam(required = false)Integer pageNum,
                                @RequestParam(required = false)Long[] shopIdList,
                                @RequestParam(required = false) String[] nameList){
        ResultModel resultModel = new ResultModel();
        Map<String, Object> customsPage = customQOProcessor.parserCustomQO(shopListCustomQOS2(pageSize,pageNum,shopIdList,nameList));
        resultModel.setData(customsPage);

        return resultModel;
    }



    public List<CustomQO> shopListCustomQOS2(Integer pageSize,
                                            Integer pageNum,
                                            Long[] shopIdList,
                                            String[] nameList){
        ArrayList<CustomQO> list = Lists.newArrayList();
        CustomQO customQO = aqoeous()
                .qoName(ItemQO.class)
                .qoJson(
                        "pageSize",pageSize,
                        "pageNum",pageNum,
                        "shopIdList",shopIdList,
                        "nameList",nameList
                )
                .build()
                ;
        list.add(customQO);

        return list;
    }



    @RequestMapping(path="/aqoeous/item/list"
            ,produces = "application/json;charset=UTF-8"
//            ,produces ="text/plain;charset=UTF-8"
    )
    @ResponseBody
    public ResultModel shopList(ItemQO itemQO){
        ResultModel resultModel = new ResultModel();
        Map<String, Object> customsPage = customQOProcessor.parserCustomQO(shopListCustomQOS(itemQO));
        resultModel.setData(customsPage);

        return resultModel;
    }

    public List<CustomQO> shopListCustomQOS(ItemQO itemQO){
        ArrayList<CustomQO> list = Lists.newArrayList();
        CustomQO customQO = aqoeous()
                .qoName(ItemQO.class)
                .qoJsonFromSO(itemQO)
                .build()
                ;
        list.add(customQO);

        return list;
    }
}
